<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE HTML>
<html>
	 <head>
		 <meta http-equiv="content-type" content="text/html;charset=utf-8">
		 <title> New Document </title>
		 <script src="/zj125/Public/Admin/order/js/jquery.js"></script>
		 <link rel="stylesheet" href="/zj125/Public/Admin/order/js/jqueryUI/jquery-ui.theme.min.css">
		 <script src="/zj125/Public/Admin/order/js/jqueryUI/jquery-ui.min.js"></script>
		<script type="text/javascript" src="/zj125/Public/Admin/order/js/admin-js.js"></script>
		 <style>
		 .biaod{margin-left:-30px}
		 .msg{background-color:#1C86EE;width:200px;height:30px;position:absolute;left:50%;margin-left:-100px;border-radius:8px;display:none;color:white}
		.v-edit{display:none}
		 </style>
	 </head>
	 <body>
		<!-- 订单详情列表表单 -->		
		<form method="post" action="" name="listForm" class="v-edit">
			<input type="hidden" name="id">
			<div id="tanchu1" style="border:4px solid #999; background-color:#FFF;" >
				<div style="line-height:25px;  font-size:16px;padding-left:40px;padding-bottom:10px;padding-top:10px;">
					<div>						
						<br/>会员电话：<input type="text" name="tel" value="">
						<br/>发票抬头：<input type="text" name="tait" value="">
						<br/>发票内容：<input type="text" name="content" value="">
						<br/>待收件人：<input type="text" name="person" value="">
					</div>
					<div style="float:left">
						详细地址：<textarea name="address" rows="" cols=""></textarea>	
					</div>					
				</div>
				<table class="list_table" id="listtable" width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CFCFCF" align="center" style="margin-top:8px">
					<thead>				 
						<tr align="center" bgcolor="#FBFCE2" height="25">
							 <th class="pname" width="18%"> 
							商品名称<img src="/zj125/Public/Admin/order/image/sort_desc.gif"/></th>
							 <th class="pro-num" width="12%">商品货号</th>
							 <th class="p_color" width="8%">颜色</th>
							 <th class="p_size" width="10%">规格</th>
							 <th class="s_price" width="10%">优惠价格</th>
							 <th class="b_price" width="10%">购买单价</th>
							 <th class="b_num" width="10%">购买数量</th>
							 <th class="p_num" width="10%">商品库存</th>
						</tr>
					</thead>
				   <tbody> 
					   <tr onMouseOver="this.style.background='#FFCC66'" onMouseOut="this.style.background='#fff';" bgcolor="#CCCCCC" id="pro">
							 <td align="center" valign="middle" class="pname" width="15%"></td>
							 <td align="center" class="pronum"></td>
							 <td align="center" class="color"></td>
							 <td align="center" class="size"></td>
							 <td align="center" class="name"></td>
							 <td align="center" class="name"></td>
							 <td align="center" class="buynum"></td>
							 <td align="center" class="onsale"></td>
					   </tr>
				   </tbody>
				</table>
				<div style="line-height:25px;padding-left:60px;padding-bottom:10px;padding-top:10px;">
				  <input type="hidden" name="ordid" value=""/>
				  <input type="hidden" name="ordnow" value=""/>
				</div>
				<div id="tanchu1" style="border:1px solid #999; background-color:#FFF;" >  
					<div style="line-height:25px; font-size:16px;padding-left:80%;padding-bottom:10px;padding-top:10px;">
						订单总金额：（<font color="blue"></font>）
						<br/>应付总金额：<font color="blue"></font>       
					</div>
				</div>
			</div>
		</form>
	 <!--订单列表显示-->
	<div class="msg" align="center"></div>
<form action="<?php echo U('orderList');?>" method="post">
	<div class="select_order" style="height:40px; width:96%;padding-left:20px;
		margin-bottom:15px;border:1px solid #ccc;font-size:14px;padding-top:6px;">
		订单号：<input type="text" name="orderid" value='' id="orderid"> 
		收货人：<input type="text" name="getperson" value=''id="getperson">
		订单状态： <select id="ordernow" name="ordernow">
		<option value="0">--全部订单--</option>
		<option value="1">--已经完成--</option>
		<option value="2">--已经付款--</option>		
		<option value="3">--已经发货--</option>	
		<option value="4">--等待发货--</option>
		<option value="5">--等待确认--</option>
		<option value="6">--等待付款--</option>		
		<option value="7">--已经取消--</option>
		</select> &nbsp;
		<input type="submit" name="sub" value="搜索"  style="border:none; background-color:#F90;cursor:pointer;"/>
	</div>
</form>
	 <!-- 订单列表表单 -->
	<div class="biaod">
	  <form method="post" action="" name="listForm"> 
		<table class="list_table" id="listtable" width="95%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CFCFCF" align="center" style="margin-top:8px">
		<thead> 
		<tr align="center" bgcolor="#FBFCE2" height="25">
			<th class="order_id">编号</th>
			<th><input id="s_all" type="checkbox">选择</th>
			<th class="order_num"> 订单号<img src="/zj125/Public/Admin/order/image/sort_desc.gif"/></th>
			<th class="order_time">下单时间</th>
			<th class="getperson">收货人</th>
			<th class="address">配送地址</th>
			<th class="money">应付金额</th>
			<th class="zhuangtai">订单状态</th>
			<th class="operate">操作</th>
		</tr>
		</thead>
		<tbody> 
		<?php echo ($s); ?>
	   <?php if(is_array($res)): $i = 0; $__LIST__ = $res;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($i % 2 );++$i;?><tr align="center" bgcolor="#FFFFFF" height="26" align="center" border=1 onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" id="order_<?php echo ($v["id"]); ?>" >
			<td><?php echo ($v["id"]); ?></td>
		    <td class="num"><input type="checkbox" name="row[]" value="<?php echo ($v["id"]); ?>" class="c1"></td>
			<td><?php echo ($v["ordid"]); ?></td>		       
			<td align="center" class="order_time"><?php echo ($v["ordtime"]); ?> </td>
			<td align="center" class="name"><span class="name"><?php echo ($v["person"]); ?></span></td>		
			<td align="center" class="address"><span class="name"><?php echo ($v["address"]); ?></span></td>
			<td align="center" class="price"><span class="price">￥<?php echo ($v["money"]); ?></span></td>
			<td align="center" class="onsale"><span class="order_now">
				<?php switch($v["ordnow"]): case "1": ?>已经完成<?php break;?>    
					<?php case "2": ?>已经付款<?php break;?>
					<?php case "3": ?>已经发货<?php break;?>    
					<?php case "4": ?>等待发货<?php break;?>
					<?php case "5": ?>等待确认<?php break;?>    
					<?php case "6": ?>等待付款<?php break;?>
					<?php case "7": ?>已经取消<?php break; endswitch;?></span>
			</td>
			<td align="center" class="operate" >
			  <a href="<?php echo U('orderdetail');?>?id=<?php echo ($v["id"]); ?>"><input type="button" border=0 value="查看" name="view" data-oid="<?php echo ($v["id"]); ?>" width=16 height=16/></a> 
			  <input type="button" border=0  value="编辑" data-oid="<?php echo ($v["id"]); ?>" name="edit" width=16 height=16>		 
			  <input type="button" border=0 value="删除"  data-oid="<?php echo ($v["id"]); ?>" name="del" width=16 height=16></td>
		   </tr><?php endforeach; endif; else: echo "" ;endif; ?>
	    <tr align="left" bgcolor="#CCCCCC">
			<td colspan=8  height="40px" id="widget2">
				<input type="button" name="add" value="添加订单">
				<input type="button" id="f_all" value="反选" >
				<input type="button" value="删除" name="dele"><div style="float:right;margin-top:10px"><?php echo ($page); ?></div>
			</td>
		</tr>
	 </tbody>
	</table>
	</form>
  </div>
		<script>
		//搜索框自动完成
		$( function() {
			 $( "#orderid" ).autocomplete({
			  source: "<?php echo U('search1');?>",			  
			});
		});

		$( function() {
			 $( "#getperson" ).autocomplete({
			  source: "<?php echo U('search2');?>",			  
			});
		});

		//全选反选
		$(function(){	
			$('#s_all').click(function(){
				$('.c1').prop('checked',$(this).prop('checked'));	
			});
		
			$('#f_all').click(function(){
				$('.c1').map(function(k,v){
					var flag = $(v).prop('checked');
					$(v).prop('checked',!flag);
				});			
			});
		});

	//删除单个弹窗
	$(function(){
	$('[name="del"]').click(function(){
		var id = $(this).attr('data-oid');
		$( "<div>确定删除吗?</div>" ).dialog({
		  resizable: false,
		  title:"删除",
		  height: "auto",
		  width: 350,
		  modal: true,
		  buttons: {
			"确认删除": function() {
			  $( this ).dialog( "close" );
			  $.get('<?php echo U("orderDel");?>',{id:id},function(data){
			if(data.status){				
				$('#order_'+id).remove();
				$('.msg').text(data.msg);
				$('.msg').slideDown('fast');
				setTimeout(function(){$('.msg').slideUp('fast');},1600);				
			}else{
				$('#order_'+id+' [name="delet"]').val('删除');
				$('.msg').text(data.msg);
				$('.msg').slideDown('fast');
				setTimeout(function(){$('.msg').slideUp('fast');},1600);
				}			
			},'json');
			refresh();
			
			},
			"取消": function() {
			  $( this ).dialog( "close" );
			}
		  }
		});
	});

	//刷新当前页面.
	function refresh(){
		window.location.reload();//刷新当前页面.				 
	}
	
	
	//可删除多个的弹窗
  $( function() {
		$('[name="dele"]').click(function(){
			var arr = [];      
		$('input:checked').each(function(){   //所有为checked状态的多选框   
			arr.push(this.value);  
		});  
		if(arr.length == 0 ){ 
		  $( '<div>请选择需要删除的记录</div>').dialog({
		  resizable: false,
		  title:"!提示",
		  height: "auto",
		  width: 350,
		  modal: true,
		  buttons: {
			"确定": function() {
				$( this ).dialog( "close" );
			
			},
		  }
		}); 
			return;  
		}  		
		var len = $("input[name='row[]']:checked").length;
		console.log(len);
		console.log(arr);
		$( '<div>确定删除这<font color="red">'+len+'</font>项吗?删除后不可恢复!</div>').dialog({
		  resizable: false,
		  title:"删除",
		  height: "auto",
		  width: 350,
		  modal: true,
		  buttons: {
			"确认删除": function() {
				$( this ).dialog( "close" );
			  $.post('<?php echo U("Del");?>',{arr:arr},function(data){
			if(data.status){				
				$("input[name='row[]']:checked").each(function() {              
				$(this).parent().parent().remove(); 
				});
				$('.msg').text(data.msg);
				$('.msg').slideDown('fast');
				setTimeout(function(){$('.msg').slideUp('fast');},1600);				
				}
			},'json');
			refresh();
			},
			"取消": function() {
			  $( this ).dialog( "close" );
			}
		  }
		});
	  });
   });
});

//编辑弹窗
$('[name="edit"]').click(function(){
		var id = $(this).attr('data-oid');
		$('.v-edit [name="id"]').val(id);
		$.get('<?php echo U("chaxun");?>',{id:id},function(data){
			console.log(data);
			if(data.ordnow == 5){
				$( '<div>已经发货不允许再编辑</div>').dialog({
		  resizable: false,
		  title:"!提示",
		  height: "auto",
		  width: 350,
		  modal: true,
		  buttons: {
			"确定": function() {
				$('.v-edit').dialog( "close" );
			
			},
		  }
		}); 
			//return;  
		}

			$('.v-edit [name="tel"]').val(data.tel);
			$('.v-edit [name="address"]').val(data.address);
			$('.v-edit [name="tait"]').val(data.tait);
			$('.v-edit [name="content"]').val(data.content);
			$('.v-edit [name="person"]').val(data.person);
			$('#pro td:eq(0)').text(data.pname);
			$('#pro td:eq(1)').text(data.pid);
			$('#pro td:eq(2)').text(data.color);
			$('#pro td:eq(3)').text(data.size);
			$('#pro td:eq(4)').text(data.sprice);
			$('#pro td:eq(5)').text(data.price);
			$('#pro td:eq(6)').text(data.num);
			$('#pro td:eq(7)').text(data.pnum);
		},'json');
		
		$( '.v-edit' ).dialog({
		  resizable: false,
		  title:"订单修改：",
		  height: "auto",
		  width: 880,
		  modal: true,
		  buttons: {
			"确认编辑":  		
				function() {
				//var ordnow = 5;
				//var express = $('.v-edit [name="express"]').val();
				//var expid = $('.v-edit [name="expid"]').val();						  
			  $.post('<?php echo U("view");?>',{id:id,ordnow:ordnow,express:express,expid:expid},function(data){
				$('#order_'+id+' td:eq(7)').text("已经发货");
				$('.msg').text(data.msg);
				$('.msg').slideDown('fast');
				setTimeout(function(){$('.msg').slideUp('fast');},1600);			
				},'json');
				$( this ).dialog( "close" );
				},
				"取消": function() {
				  $( this ).dialog( "close" );
			}
		  }
		});
		
	});
		</script>
	 </body>
</html>